const store = require("./store/优化/index-优化")

//直接订阅数据，不需要每次再手动进行getState
const unsubscribe = store.subscribe(() => {
   console.log("订阅数据的变化:", store.getState());
})

store.dispatch({ type: 'change_name', name: "张三"})
//重复代码：
store.dispatch({ type: 'change_name', name: "李四"})
store.dispatch({ type: 'change_name', name: "王五"})


//优化：创建actionCreators: 帮助我们动态生成action
const changeNameAction = (name) => {
  return {
    type: "change_name",
    name: name
  }
}

//通过一个函数封装action, 添加处理逻辑
store.dispatch(changeNameAction("张三"))
store.dispatch(changeNameAction("李四"))
store.dispatch(changeNameAction("王五"))


const addNumberAction = (counter) =>({
  type: "add_number",
  counter
})

store.dispatch(addNumberAction(5))
store.dispatch(addNumberAction(10))
store.dispatch(addNumberAction(15))
